<?php
/**
 * Created by PhpStorm.
 * User: skytop
 * Date: 16-8-27
 * Time: 上午8:01
 */
namespace Admin\Model;
use Think\Verify;

class Captcha{
    //定义常量

    //注册验证码
    const REGISTER_CAPTCHA=1;

    //登陆验证码
    const LOGIN_CAPTCHA=2;

    //创建验证码register
    /**
     * @param int $identify 注册1或是登陆2
     */
    public static function createCaptcha($identify=self::REGISTER_CAPTCHA){
        //对验证码进行设置
        $config=array(
          'length'=>C('captcha_length')
        );

        $verify=new Verify($config);

        //生成验证码
        $verify->entry($identify);
    }

    /**
     * @param $captcha          用户输入的验证码
     * @param int $identify     注册或是登陆时的验证码
     * @return bool             false|true
     */
    public static function checkCaptcha($captcha,$identify=self::REGISTER_CAPTCHA){
        $verify=new Verify();
        return $verify->check($captcha,$identify);
    }
}